package com.shiro.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.shiro.utils.Hash;
import com.shiro.web.model.Json;
import com.shiro.web.model.User;
import com.shiro.web.service.RoleService;
import com.shiro.web.service.UserService;

@Controller
@RequestMapping("test")
public class TestController {

	@Autowired
	private UserService userService;

	@Autowired
	private RoleService roleService;
	
	@RequestMapping
	@ResponseBody
	public Json test() {
		Json json = new Json();
		json.setSuccess(true);
		json.setMsg("测试成功");
		json.setObj(roleService.query());
		return json;
	}

	@RequestMapping("register")
	@ResponseBody
	public Json register(User user) {
		Json json = new Json();
		user.setPassword(Hash.md5(user.getPassword()));
		int re = userService.register(user);
		json.setSuccess(re > 0);
		json.setObj(user);
		return json;
	}
}
